#include <stdio.h>

//打印路径
void printfPath(int path[],int len)
{
    for(int i = 0; i < len; i++)    //len为路径长度
    {
        printf("%d",path[i]);   //打印每一条路径的每一步
        if(i < len - 1)//->会比len少一
            printf("->");
    }
    printf("\n");
}

//计算总跳法，step为路径的长度
int jumpWays(int n,int path[],int step)
{
    //小于0的直接返回
    if(n < 0)
        return 0;
    
    if(n == 0)
    {
        if(step != 0)
        {
            printfPath(path,step);
            return 1;
        }
        else
            return 0;
    }

    int ways = 0;
    for(int i = 1; i <= 3; i++)
    {
        path[step] = i;
        ways += jumpWays(n - i,path,step +1);
    }
    return ways;
}

int main(int argc, char const *argv[])
{
    int n;
    int path[100];
    printf("请输入台阶的级数n：\n");
    scanf("%d",&n);

    printf("总跳法:%d\n",jumpWays(n,path,0));

    return 0;
}
